using System;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EGym10.Relatorios
{
    public partial class Cadastros_Custos : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void grdMain_DataBound(object sender, EventArgs e)
        {
            var lblTotal = (Label) grdMain.FooterRow.Cells[3].FindControl("lblTotal");
            lblTotal.Text = "0,00";

            foreach (GridViewRow row in grdMain.Rows)
            {
                var lblValor = (Label) row.Cells[3].FindControl("lblValor");
                lblTotal.Text = Convert.ToString(Convert.ToDouble(lblTotal.Text) + Convert.ToDouble(lblValor.Text));
            }
            foreach (GridViewRow row in grdMain.Rows)
            {
                var lblValor = (Label) row.Cells[3].FindControl("lblValor");
                var lblPIdeal = (Label) row.Cells[4].FindControl("lblPIdeal");
                var lblPTolerancia = (Label) row.Cells[6].FindControl("lblPTolerancia");
                var lblPTotal = (Label) row.Cells[5].FindControl("lblPTotal");

                lblPTotal.Text = Convert.ToString((Convert.ToDouble(lblValor.Text)/Convert.ToDouble(lblTotal.Text))*100);
                if (Convert.ToDouble(lblPTotal.Text) > Convert.ToDouble(lblPIdeal.Text))
                {
                    if (Convert.ToDouble(lblPTotal.Text) >
                        (Convert.ToDouble(lblPIdeal.Text) + Convert.ToDouble(lblPTolerancia.Text)))
                        row.ForeColor = Color.Red;
                    else
                        row.ForeColor = Color.Green;
                }
                else
                    row.ForeColor = Color.Blue;
            }
        }
    }
}